<?php
require_once ("../src/db/connectdatabase.php");
function getBanks() {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('bankid', 'bankname', 'banklogo', 'datecreate');
	$condetion = array('isuse' => true);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}

function int_to_date($int)
{
    $time  = date("d/m/Y", $int);
    return $time;
}
?>
<style>
.stylestt {
	width: 80px;
	max-width: 80px;
	text-align: center;
}

.listbanksviewcontent table {
	width: 850px;
	max-width: 850px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table td img {
	cursor: pointer;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylemabank {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.stylenamebank {
	padding-left: 5px;
	padding-right: 5px;
	width: 350px;
	max-width: 350px;
}

.stylelogobank {
	width: 100px;
	text-align: center;
	max-width: 100px;
}

.styleacctionbank {
	width: 150px;
	text-align: center;
	max-width: 150px;
}

.styledatecreatebank {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.nameformbank {
	background: url(../images/bg-login.png);
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
}

table tr:hover td {
	background: #FFC;
}

.showbanklistdeletedclick {
	color: #FFF;
	font-weight:bold;
	padding: 5px;background:#999; 
	-moz-border-radius: 5px 5px 5px 5px; 
	-webkit-border-radius: 5px 5px 5px 5px; 
	border-radius: 5px 5px 5px 5px; 
	cursor: pointer;
}

.reveal-modal-bg { 
	position: fixed; 
	height: 100%;
	width: 100%;
	background: #000;
	background: rgba(0,0,0,.8);
	z-index: 100;
	display: none;
	top: 0;
	left: 0; 
}
		
#showlistbankdeletedlightbox {
	display: none;
	top: 0px; 
	left: 50%;
	margin-left: -400px;
	width: 800px;
	background: #eee url(../modal-gloss.png) no-repeat -200px -80px;
	position: absolute;
	z-index: 101;
	padding: 0px 0px 0px;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow: 0 0 10px rgba(0,0,0,.4);
	-webkit-box-shadow: 0 0 10px rgba(0,0,0,.4);
	-box-shadow: 0 0 10px rgba(0,0,0,.4);
}

#showlistbankdeletedlightbox .close-reveal-modal {
	font-size: 22px;
	line-height: .5;
	position: absolute;
	top: 8px;
	right: 11px;
	color: #aaa;
	text-shadow: 0 -1px 1px rbga(0,0,0,.6);
	font-weight: bold;
	cursor: pointer;
} 
.reveal-modal-title {
    background: url('../images/box-title-blue.jpg') repeat-x;
    height: 50px;
    text-align: center;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
}

.reveal-modal-title h1 {
    color: white;
}

.reveal-modal-main {
    padding: 20px;
	min-height: 400px;
	max-height: 400px;
	overflow-y: scroll;
}
</style>
<h3>Danh Sách Các Ngân Hàng</h3>
<div style="float:right"><span class="showbanklistdeletedclick">Hiển Thị Ngân Hàng Đã Xóa</span></div><br /><br />
<div class="listbanksviewcontent">
<table>
	<tr>
    	<th class="stylestt title">STT</th>
    	<th class="stylemabank title">Mã</th>
        <th class="stylenamebank title">Tên Ngân Hàng</th>
        <th class="stylelogobank title">Logo</th>
        <th class="styledatecreatebank title">Ngày C.Nhật</th>
        <th class="styleacctionbank title">Chức năng</th>
    </tr>
    <?php
	$arraybanks = getBanks();
	$i = 1;
	foreach ($arraybanks as $value) {
		echo('<tr><td class="stylestt nameformbank">'.$i.'</td><td class="stylemabank nameformbank">'.$value[0].'</td><td class="stylenamebank nameformbank">'.$value[1].'</td><td class="stylelogobank nameformbank"><img width="95px;" src="../'.$value[2].'" /></td><td class="styledatecreatebank nameformbank">'.int_to_date($value[3]).'</td><td class="styleacctionbank nameformbank"><img class="class-editbank-link" src="../images/icon-edit.gif" title="Chỉnh Sửa '.$value[1].'" />&nbsp; | &nbsp;<img class="class-deletebank-link" src="../images/icon-delete.gif" title="Xóa '.$value[1].'" /></td></tr>');
		$i++;
	}
	?>
</table>
</div>
<div><a href="../admin.php?content=quanlinganhang&amp;&amp;adrt=addbank"><img src="../images/icon-add.jpg" title="Thêm Ngân Hàng" />Thêm Ngân Hàng</a></div>
<div class="reveal-modal-bg"></div>
<div id="showlistbankdeletedlightbox">
	<div class="reveal-modal-title"><h1>Danh Sách Ngân Hàng Đã Xóa</h1></div><br />
    <div class="reveal-modal-main">
    	
    </div>
    <a class="close-reveal-modal">&#215;</a>
</div>
<script>
	$(document).on('click', '.class-editbank-link', function(e) {
		elem = $(this)
		var idbank = elem.parent().siblings('.stylemabank').text();
		window.location= 'admin.php?content=quanlinganhang&&adrt=editbank&&id=' + idbank;
	});
	
	$(document).on('click', '.class-deletebank-link', function(e) {
		elem = $(this)
		var idbank = elem.parent().siblings('.stylemabank').text();
		if(confirm("Bạn có muốn xóa?")) {
			$.ajax({
				url: "../src/ajax/ajaxbank.php",
				type: "post",
				data: {act:'delbank', idre: idbank},
				dataType:"json",
				success: function(data) {
					if(data == true) {
						elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
					} else {
						alert("Cập nhật dữ liệu không thành công");
					}
				}
			});
		}
	});
	
	$(document).on('click', '.showbanklistdeletedclick', function(e) {
		$('.reveal-modal-bg').show();
		$('#showlistbankdeletedlightbox').show();
		$('.reveal-modal-main').html('<table><tr><th class="stylemabank title">Mã</th><th class="stylenamebank title">Tên Ngân Hàng</th><th class="stylelogobank title">Logo</th><th class="styleacctionbank title">Khôi Phục</th></tr><tr class="listbanksdeletedempty"><th colspan="5">Không tồn tại ngân hàng nào đã xóa</th></tr></table>');
		// load ajax 
		$.ajax({
			url: "../src/ajax/ajaxbank.php",
			type: "post",
			data: {act:'getbanksdeleted'},
			dataType:"json",
			success: function(response) {
				if(response.length > 0) {
					$('.listbanksdeletedempty').remove();
				}
				$.each(response, function(entryIndex, entry){
					insertrowbankdeleted(entry[0], entry[1], entry[2], entry[3]);
				});
			}
		});
		
	});
	
	$(document).on('click', '.close-reveal-modal', function(e) {
		clostshowbankdeleted();
	});
	
	$(document).on('click', '.reveal-modal-bg', function(e) {
		clostshowbankdeleted();
	});
	
	function clostshowbankdeleted() {
		$('.reveal-modal-bg').hide();
		$('#showlistbankdeletedlightbox').hide();
	}
	
	function insertrowbankdeleted(mabank, tenbank, logo, ngaycapnhat) {
		var html = '<tr><td class="stylemabank nameformbank">' + mabank + '</td><td class="stylenamebank nameformbank">' + tenbank + '</td><td class="stylelogobank nameformbank"><img width="95px;" src="../' + logo + '" /></td><td class="styleacctionbank nameformbank"><img class="class-restorebank-link" src="../images/icon-edit.gif" title="Khôi Phục" />&nbsp;</td></tr>';
		
		$('.reveal-modal-main table').append(html).children('.reveal-modal-main table tr:last').hide().fadeIn(300);
	}
	
	// restore lai ngan hang
	$(document).on('click', '.class-restorebank-link', function(e) {
		elem = $(this)
		var idbank = elem.parent().siblings('.stylemabank').text();
		if(confirm("Bạn có khôi phục lại ngân hàng " + idbank + "?")) {
			$.ajax({
				url: "../src/ajax/ajaxbank.php",
				type: "post",
				data: {act:'restorebank', idre: idbank},
				dataType:"json",
				success: function(data) {
					if(data == true) {
						alert("Vui lòng nhấn F5 để thấy sự thay đổi, trên danh sách!");
						elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
					} else {
						alert("Cập nhật dữ liệu không thành công");
					}
				}
			});
		}
	});
	
</script>